home *** CD-ROM | disk | FTP | other *** search
/ CD Actual Thematic 7: Programming / CDAT7.iso / demos / VisualAge for Java 2.0 Entry / setup / data1.cab / ide-e / IDE / cache / 147PWHG (.txt) < prev    next >
Encoding:
Java Class File  |  1998-09-16  |  2.6 KB  |  62 lines

  1. package com.ibm.uvm.abt.edit;
  2.  
  3. import java.awt.Component;
  4. import java.awt.Font;
  5. import java.beans.PropertyEditorSupport;
  6. import java.util.ResourceBundle;
  7.  
  8. public class FontEditor extends PropertyEditorSupport {
  9.    private static ResourceBundle resabtedit = ResourceBundle.getBundle("com/ibm/uvm/abt/edit/abtedit");
  10.    FontPropertyEditor customEditor = null;
  11.  
  12.    public String getAsText() {
  13.       Font font = (Font)this.getValue();
  14.       String strStyle;
  15.       if (font.isBold()) {
  16.          strStyle = font.isItalic() ? resabtedit.getString("bolditalic") : resabtedit.getString("bold");
  17.       } else {
  18.          strStyle = font.isItalic() ? resabtedit.getString("italic") : resabtedit.getString("plain");
  19.       }
  20.  
  21.       return font.getName() + ", " + strStyle + ", " + font.getSize();
  22.    }
  23.  
  24.    public Component getCustomEditor() {
  25.       if (this.customEditor == null) {
  26.          Font aFont = (Font)this.getValue();
  27.          if (aFont == null) {
  28.             this.customEditor = new FontPropertyEditor();
  29.          } else {
  30.             this.customEditor = new FontPropertyEditor(aFont);
  31.          }
  32.       }
  33.  
  34.       return this.customEditor;
  35.    }
  36.  
  37.    public String getJavaInitializationString() {
  38.       Font font = (Font)this.getValue();
  39.       return "new java.awt.Font(\"" + font.getFamily() + "\", " + font.getStyle() + ", " + font.getSize() + ")";
  40.    }
  41.  
  42.    public Object getValue() {
  43.       return this.customEditor != null ? this.customEditor.getFontValue() : super.getValue();
  44.    }
  45.  
  46.    public void setAsText(String text) throws IllegalArgumentException {
  47.       throw new IllegalArgumentException(text);
  48.    }
  49.  
  50.    public void setValue(Object newValue) {
  51.       super.setValue(newValue);
  52.       if (this.customEditor != null) {
  53.          this.customEditor.setFontValue((Font)newValue);
  54.       }
  55.  
  56.    }
  57.  
  58.    public boolean supportsCustomEditor() {
  59.       return true;
  60.    }
  61. }
  62.